package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * 集合的排序
 * 集合的工具类Collections提供了一个静态方法sort，可以对List集合进行自然排序（从小到大排序）
 * 升序加反转即可从大到小
 */
public class SortListDemo {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        Random random = new Random();
        for(int i=0;i<10;i++){
            list.add(random.nextInt(100));
        }
        System.out.println(list);//[24, 57, 48, 5, 51, 54, 54, 79, 96, 92]
        Collections.sort(list);
        System.out.println(list);//升序[5, 24, 48, 51, 54, 54, 57, 79, 92, 96]
        Collections.sort(list,(i1,i2)->
                i2-i1
                );
        System.out.println(list);//降序[94, 91, 87, 75, 69, 69, 48, 29, 18, 1]
        Collections.shuffle(list);//乱序(洗牌)
        System.out.println(list);//[23, 52, 63, 23, 38, 99, 79, 98, 98, 39]


    }
}
